﻿//Write a program that reads an integer number and calculates and prints its square root.
//If the number is invalid or negative, print "Invalid number".
//In all cases finally print "Good bye". Use try-catch-finally.


using System;

public class SquareRootOfIntegerNumber
{
    public static void Main(string[] args)
    {
        try
        {
            Console.Write("Enter integer number n = ");
            string userString = Console.ReadLine();
            int number = int.Parse(userString);
            Console.WriteLine();
            double sqrt = CalculateSqrt((double)number);

            Console.Write("Square root of {0} = {1}", number, sqrt);
            Console.WriteLine();
        }
        catch (ArgumentNullException)
        {
            Console.WriteLine("Invalid number!Number is missing!!!");
        }
        catch (FormatException)
        {
            Console.WriteLine("Invalid number!");
        }
        catch (ArgumentException)
        {
            Console.WriteLine("Invalid number! The number must not be negative!!!");
        }
        catch (OverflowException)
        {
            Console.WriteLine("Invalid number! The number is too big!!!");
        }
        finally
        {
            Console.WriteLine("Good bye!!!");
        }
    }

    private static double CalculateSqrt(double number)
    {
        if (number < 0)
        {
            throw new ArgumentException();
        }

        return Math.Sqrt(number);
    }
}
